import {EventEmitter, OnInit, Output} from '@angular/core';
import {FormGroup} from '@angular/forms';
import {BaseComponent} from './BaseComponent';

export abstract class BaseFilter extends BaseComponent implements OnInit {
  filterForm: FormGroup;
  isCollapse = false;

  @Output() onSearch = new EventEmitter<{ params: object }>();


  /**
   * 初始化默认查询条件
   */
  getDefaultFilter() {
    return {};
  }

  getParams() {
    const params = this.filterForm.value;
    Object.assign(params, this.getDefaultFilter());
    return params;
  }

  ngOnInit() {
  }

  resetFilterForm() {
    this.filterForm.reset(this.getDefaultFilter());
  }

  _toggleCollapse() {
    this.isCollapse = !this.isCollapse;
  }
}
